<template>
	<view class="min-h-full p-10 static">
		<view class="flex flex-row flex-wrap rounded-lg bg-white" style="min-height: 80vh;box-shadow: 0 0 8px 0px rgba(0,0,0,0.3)">
			<view class="w-full p-20 text-14" style="color: #5E5E5E;">
				<view class="bottom-line pt-12 pb-12 flex flex-row align-items-center">
					<text class="text-bold">最高学历：</text>
					<picker class="flex-1" @change="educationChange" :value="education_index" :range="education_list">
						<text v-if="education" class="">{{education}}</text>
						<text v-else class="" style="color:#B8B8B8">请选择</text>
					</picker>
				</view>
				<view class="bottom-line pt-12 pb-12 flex flex-row align-items-center">
					<view class="text-bold">CAAC证书编号：</view>
					<input class="flex-1 text-14" type="text" placeholder="请输入证书编号" placeholder-style="color:#B8B8B8" v-model="caac_certificate_no"></input>
				</view>
				<view class="bottom-line pt-12 pb-12 flex flex-row align-items-center">
					<view class="text-bold">UTC证书编号：</view>
					<input class="flex-1 text-14" type="text" placeholder="请输入证书编号" placeholder-style="color:#B8B8B8" v-model="utc_certificate_no"></input>
				</view>
				<view class="bottom-line pt-12 pb-12 flex flex-row align-items-start" >
					<view class="text-bold" style="line-height: 1.4rem;">其他证书：</view>
					<view class="flex-1" >
						<input class=" text-14"  type="text" placeholder="请输入证书名称" placeholder-style="color:#B8B8B8" v-model="other_certificate_name"></input>
						<input class=" text-14 mt-8"  type="text" placeholder="请输入证书编号" placeholder-style="color:#B8B8B8" v-model="other_certificate_no"></input>
					</view>
				</view>
				<view class="w-full rounded-sm text-bold text-white text-center text-16 mt-20" style=" height:80rpx; line-height: 80rpx; background-color: #006BFF;" @tap="saveInfo">保存</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '/utils/request.js';
	import { mapState, mapMutations } from 'vuex'
	export default {
		data() {
			return {
				education_list: ['初中', '高中/中专', '大专', '本科', '研究生', '博士'],
				education_index: 0,
				education: '',
				caac_certificate_no: '',
				utc_certificate_no: '',
				other_certificate_name: '',
				other_certificate_no: '',
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		onLoad() {
			this.education = this.userInfo.education
			this.caac_certificate_no = this.userInfo.caac_certificate_no
			this.utc_certificate_no = this.userInfo.utc_certificate_no;
			this.other_certificate_name = this.userInfo.other_certificate_name;
			this.other_certificate_no = this.userInfo.other_certificate_no;
			if(!this.userInfo.phone){
				uni.showToast({
					title: '请先登录',
					icon: 'none',
				})
				setTimeout(()=>{
					uni.navigateBack()
				}, 1000)
			}
		},
		onReachBottom() {
			
		},
		onShareAppMessage() {
			return {
			  title: '飞兔接单',
			  path: '/pages/task/list',
			  // imageUrl : ''
			}
		},
		onShareTimeline() {
			return {
			  title: '飞兔接单',
			  // query: '',
			  // imageUrl : ''
			}
		},
		methods: {
			...mapMutations(['login', 'setUserInfo']),
			// 修改学历选择
			educationChange(e){
				this.education_index = e.detail.value;
				this.education = this.education_list[this.education_index];
			},
			// 保存信息
			saveInfo(){
				request.post('/pilot/saveInfo', {
					education: this.education,
					caac_certificate_no: this.caac_certificate_no,
					utc_certificate_no: this.utc_certificate_no,
					other_certificate_name: this.other_certificate_name,
					other_certificate_no: this.other_certificate_no,
				}).then(res=>{
					uni.showToast({
						title: '保存成功'
					})
					request.post('pilot/userInfo').then(res=>{
						this.setUserInfo(res);
						setTimeout(()=>{
							uni.navigateBack()
						}, 1000)
					})
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #FFF8F5;
	}
	.bottom-line{
		border-bottom: 1px solid #bbb;
	}
</style>
